package com.ruoyi.ipms_crm.controller;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.ipms_crm.entity.IpmsTracking;
import com.ruoyi.ipms_crm.service.IIpmsTrackingService;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 客服回访Controller
 *
 * @author qs
 * @date 2022-04-21
 */
@RestController
@RequestMapping("/crm/tracking")
public class IpmsTrackingController extends BaseController {

    @Autowired
    private IIpmsTrackingService ipmsTrackingService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    public TableDataInfo list(IpmsTracking ipmsTracking) {
        startPage();
        List<IpmsTracking> list = ipmsTrackingService.selectIpmsTrackingList(ipmsTracking);
        return getDataTable(list);
    }


    /**
     * 获取详细信息
     */
    @GetMapping(value = "/{trackingId}")
    public AjaxResult getInfo(@PathVariable("trackingId") Integer trackingId) {
        return AjaxResult.success(ipmsTrackingService.selectIpmsTrackingByTrackingId(trackingId));
    }

    /**
     * 新增
     */
    @PostMapping
    public AjaxResult add(@RequestBody IpmsTracking ipmsTracking) {
        System.out.println("******************新增回访"+ipmsTracking);
        return toAjax(ipmsTrackingService.insertIpmsTracking(ipmsTracking));
    }

    /**
     * 修改
     */
    @PutMapping
    public AjaxResult edit(@RequestBody IpmsTracking ipmsTracking) {
        return toAjax(ipmsTrackingService.updateIpmsTracking(ipmsTracking));
    }

    /**
     * 删除
     */
    @DeleteMapping("/{trackingIds}")
    public AjaxResult remove(@PathVariable Integer[] trackingIds) {
        return toAjax(ipmsTrackingService.deleteIpmsTrackingByTrackingIds(trackingIds));
    }

    @GetMapping("/customer/{customerId}")
    public TableDataInfo trackingList(@PathVariable("customerId") Integer customerId) {
        List<IpmsTracking> list = ipmsTrackingService.selectCustomerTracking(customerId);
        System.out.println(list);
        return getDataTable(list);
    }
}
